﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manager_Sanpham1_Controls_UC_Loaisanpham : System.Web.UI.UserControl
{
    BUS_Product data = new BUS_Product();
    BUS_Manufacturer data2 = new BUS_Manufacturer();
    protected void Page_Load(object sender, EventArgs e)
    {
        hplXemloaiSP.NavigateUrl = "../Loaisanpham.aspx?id_nsx=" + Request.QueryString["id_nsx"];
        hplThemsanpham.NavigateUrl = "../Themsanpham.aspx?id_nsx=" + Request.QueryString["id_nsx"];
        hplSualoiSP.NavigateUrl = "../Sualoaisanpham.aspx?id_nsx=" + Request.QueryString["id_nsx"];
        if (!IsPostBack)
        {
            string id_nsx = Request.QueryString["id_nsx"].ToString();
            //lblXemloaisanpham.Text = "~/Manager/Sanpham/Xemsanpham.aspx?id_nsx="+id_nsx;
            //Label1.Text = id_nsx;
            GVTheoLoai.DataSource = data.Product_GetByTop(0, "Manufacturer_Id=" + id_nsx, "[Order]");
            GVTheoLoai.DataBind();
            //Response.Write(Eval(id_nsx));
        }
    }
    public string trangthai(bool tt)
    {
        if (tt)
        {
            return "Mở";
        }
        else
            return "Đóng";

    }
    public string getUrl(string Id_nsx, string id_sp)
    {
        return "~/Manager/Sanpham/Xemsanpham.aspx?id_nsx=" + Id_nsx + "&id_sp=" + id_sp;
    }
    //public string geturlSualoaisanpham()
    //{
    //    string id_nsx = Request.QueryString["id_nsx"].ToString();
    //    return "~/Manager/Sanpham/Sualoaisanpham.aspx?id_nsx=" + id_nsx;
    //}
    
    //protected void btnXoa_Click(object sender, EventArgs e)
    //{
    //    //abc();
    //}
    public string Status(bool tt)
    {
        if (tt)
        {
            return "Đóng";
        }
        else
        {
            return "Mở";
        }
    }
    protected void GVTheoLoai_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Sua")
        {
            string id_nsx = Request.QueryString["id_nsx"].ToString();
            Page.Response.Redirect("~/Manager/Sanpham/Suasanpham.aspx?id_nsx="+id_nsx+"&id_sp=" + e.CommandArgument);
        }
        else if (e.CommandName == "Đóng")
        {
            //data.Product_Delete(e.CommandArgument.ToString());
            data.Product_Update(e.CommandArgument.ToString(),"[Status] = 0");
            Response.Redirect(Request.RawUrl);
        }
        else if (e.CommandName == "Mở")
        {
            //data.Product_Delete(e.CommandArgument.ToString());
            data.Product_Update(e.CommandArgument.ToString(), "[Status] = 1");
            Response.Redirect(Request.RawUrl);
        }
    }
}